<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>预约上下线</title>
    <%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/public_input.jsp" %>
    <%@ include file="/common/public.jsp" %>

    <script type="text/javascript" src="${ctx}/js/validate/jquery.validate.js"></script>
    <script type="text/javascript" src="${ctx}/js/validate/messages_cn.js"></script>
    <script>
        $(document).ready(function() {

            /* $("#inputForm").validate({
             onsubmit: true,
             rules: {
             name:{
             required:true,
             maxlength:50
             },
             code:{
             required:true,
             maxlength:100
             }
             },
             messages: {
             name:{
             remote:'名称已存在'
             },
             code:{
             remote:'编码已存在'
             }
             }
             });*/
        });
    </script>
    <style>
    #ul-platform {margin: 0; width: 510px;}
    #ul-platform li {margin: 0; float: left; width: 168px;}
    #ul-location {margin: 0; width: 510px;}
    #ul-location li {margin: 0; float: left; width: 101px;}
    </style>
</head>

<body>
<div class="div-tabs-nav">
    <ul class="ui-tabs-nav">
        <li class="ui-tabs-selected">预约上下线</li>
    </ul>
</div>

<div class="ui-tabs-panel">
    <form id="inputForm" action="${ctx}/reservation/save.action" method="post">
        <div id="message"><s:actionmessage theme="custom" cssClass="success"/></div>
        <div>预约上下线<s:if test="id!=null">信息</s:if><s:else>创建</s:else></div>
        <table class="noborder">
            <s:if test="id!=null">
                <tr>
                    <td>ID:</td>
                    <td>
                        <s:textfield name="id" id="id" size="40" readonly="true" />
                    </td>
                </tr>
            </s:if>
            <tr>
                <td>类型:</td>
                <td>
                    <s:radio list="@com.iqiyi.pps.epg.core.model.reservation.ReserveControl@TYPE_MAP" name="type"></s:radio>
                </td>
            </tr>
            <tr>
                <td>频道ID:</td>
                <td>
                    <s:textfield name="fatherId" id="fatherId" readonly="true" />
                </td>
            </tr>
            <tr>
                <td>平台:</td>
                <td>
                    <ul id="ul-platform">
                        <s:iterator value="channelPlatformConfigs" id="entity">
                            <li><label><input type="radio" name="platform" value="<s:property value="#entity.key" />"<s:if test="#entity.checked != 1">disabled</s:if> /><s:property value="#entity.val" /></label></li>
                        </s:iterator>
                    </ul>
                </td>
            </tr>
            <tr>
                <td>频道名:</td>
                <td>
                    <s:textfield name="channelName" id="channelName" />
                </td>
            </tr>
            <tr>
                <td>开始时间:</td>
                <td>
                    <s:textfield name="startTime" id="startTime" onFocus="WdatePicker({dateFmt:'HH:mm:ss'})" />
                </td>
            </tr>
            <tr>
                <td>结束时间:</td>
                <td>
                    <s:textfield name="endTime" id="endTime" onFocus="WdatePicker({dateFmt:'HH:mm:ss'})" />
                </td>
            </tr>
            <tr>
                <td>开始日期:</td>
                <td>
                    <s:textfield name="startDay" id="startDay" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" />
                </td>
            </tr>
            <tr>
                <td>结束日期:</td>
                <td>
                    <s:textfield name="endDay" id="endDay" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" />
                </td>
            </tr>
            <tr>
                <td>直播延时:</td>
                <td>
                    <s:textfield id="delayTime" name="delayTime" />
                </td>
            </tr>
            <tr>
                <td>上下线状态:</td>
                <td>
                    <s:radio list="@com.iqiyi.pps.epg.core.model.reservation.ReserveControl@OPSSTATUS_MAP" name="opsStatus" />
                </td>
            </tr>
            <tr>
                <td>地区黑名单</td>
                <td>
                    <ul id="ul-location">
                        <s:iterator value="locationConfigs" id="entity">
                            <li><label><input type="checkbox" name="blacklist" value="<s:property value="key" />" /><s:property value="value" /></label></li>
                        </s:iterator>
                    </ul>
                </td>
            </tr>
            <tr>
                <td>备注:</td>
                <td>
                    <s:textarea name="reason" id="reason" cols="36" />
                </td>
            </tr>
        </table>
        <div align="left">
            <security:authorize ifAnyGranted="AUTH_MANAGER_AUTH,AUTH_ALL">
                <input class="button" type="button" onclick="save()" value="提交"/>&nbsp;
                <script>
                function save() {
                    var d = {};
                    $(".noborder input[type=text]").each(function() {
                        d[$(this).attr("name")] = $(this).val();
                    });
                    d["type"] = $(".noborder input[name=type]:checked").val();
                    d["platform"] = $("#ul-platform input:radio:checked").val();
                    d["opsStatus"] = $(".noborder input[name=opsStatus]:checked").val();
                    d["reason"] = $("#reason").val();
                    d["blacklist"] = "";
                    $("#ul-location input:checkbox:checked").each(function() {
                        d["blacklist"] += $(this).val() + ",";
                    });
                    d["channelId"] = d["fatherId"];
                    // console.log(d);
                    var host = "<s:property value="apiHost" />";
                    $.ajaxSetup({
                        beforeSend: function(xhr) {
                            xhr.setRequestHeader("From", "show");
                            xhr.setRequestHeader("Time", Math.round(new Date().getTime() / 1000));
                            xhr.setRequestHeader("Sign", "#f93Uc31K24()_@");
                        }
                    });
                    $.ajax({
                        url : host + "/reservation?callback=jsonp",
                        type : "POST",
                        data : d,
                        dataType : "jsonp",
                        jsonpCallback : "jsonp",
                        success : function(jsonObj, textStatus, xhr) {
                            if (jsonObj.code == "A00000") {
                                alert("设置成功");
                                parent.entityManagementSelf.refresh;
                            } else {
                                alert(jsonObj.msg);
                            }
                        },
                        error : function(xhr, textStatus, errorThrown) {
                            console.log("HTTP Status: " + xhr.status);
                            console.log("Error textStatus: " + textStatus);
                            console.log("Error thrown: " + errorThrown);
                            alert("error");
                        }
                    });
                }
                </script>
            </security:authorize>
            <input type="reset" class="input-button" value="重置"/>
        </div>
    </form>
</div>
</body>
</html>